<?php

########################################################################################
# Empresa :     Tecnopac Informatica;                                                  #
# Autor:        Deiverson Pacheco;                                                     #
# Data Criação: 18/12/2010;                                                            #
########################################################################################
session_start();
header("Cache-control: private");
include_once("../../includes/session.php");


//Linha para formatação de caracteres com acentuação
header("Content-Type: text/html; charset=ISO-8859-1",true);

//======================================================================================
//==> Include obrigatórias no script
//======================================================================================
include_once('../../includes/classes/class.TemplatePower.php');
include_once('../../includes/classes/class.Conexao.php');
include_once('../../includes/classes/class.Geral.php');

//======================================================================================
//==> Inicializar Classes
//======================================================================================
$not  = new Persist;
$data = new getData;
$cor  = new ColorTr;
$util = new Util;
$vld  = new ValidarDados;
$sql  = new SqlInjection;
//===================================================================================================

$id  = @$sql->tratar($_GET['id'], 30);

//incluindo o arquivo do fpdf
include_once('../../includes/classes/fpdf/class.Fpdf.php');

//defininfo a fonte !
define('FPDF_FONTPATH','../../includes/classes/fpdf/font/');

//instancia a classe.. P=Retrato, mm =tipo de medida utilizada no casso milimetros, tipo de folha =A4

//define o TOP MARGIN
$pdf = new FPDF("L","mm","A4");

$pdf->SetTopMargin(15);
$pdf->SetLeftMargin(8);
$pdf->SetRightMargin(5);

//posicao vertical no caso -1.. e o limite da margem
$pdf->SetY("-1");

$pessoa		 		= @trim(strtoupper($_GET['pessoa']));
$idcategoria 		= @trim(strtoupper($_GET['idcategoria']));
//$relatorio	 		= @trim(strtoupper($_GET['relatorio']));
extract($_GET);	

//$data_ini = $data->getDataFormatada($dtinicial);
//$data_fim = $data->getDataFormatada($dtfinal);


	$titulo = utf8_decode('Relatório Sintético de Contatos');
	
	$pdf->SetFont('arial','',10);
	$pdf->Cell(280,1,'','B',1,'C');
	$pdf->Ln(0);		
	
	$pdf->SetFont('arial','B',12);
	$pdf->Cell(280,5,$titulo,0,1,'C');
		
	$pdf->SetFont('arial','',10);
	$pdf->Cell(280,1,'','T',1,'C');
	$pdf->Ln(1);




//---------------------------------------------------------------------------------------------		
// SQL
//---------------------------------------------------------------------------------------------		

		
	extract($_GET);	
	$not->sql = " select cadastro.id, cadastro.pessoa, cadastro.nome_razao, cadastro.residencial, cadastro.celular, 
				cadastro.email, cadastro.website, categorias_associadas.id_cat, categorias.id, categorias.categoria
				from cadastro
				inner join categorias_associadas on cadastro.id = categorias_associadas.id_cadastro
				inner join categorias on categorias_associadas.id_cat = categorias.id
				where cadastro.ativo = 'Sim' ";
				
	if($pessoa != ""){
		$not->sql .= " and cadastro.pessoa = ".$pessoa." ";
	}
	if($idcategoria != ""){
		$not->sql .= " and categorias.id = ".$idcategoria." ";
	}
	
	$not->sql .= " group by cadastro.id ";		
		
	$pdf->SetX(10);
	$pdf->SetFont('arial','',10);
	$pdf->Cell(10,3,(utf8_decode('Nome / Razão Social')),0,0,'L');
	$pdf->Ln(0);
	
	$pdf->SetX(90);
	$pdf->SetFont('arial','',10);
	$pdf->Cell(90,3,(utf8_decode('Tel. Residencial')),0,0,'L');
	$pdf->Ln(0);	
	
	$pdf->SetX(125);
	$pdf->SetFont('arial','',10);
	$pdf->Cell(125,3,(utf8_decode('Celular')),0,0,'L');
	$pdf->Ln(0);			

	$pdf->SetX(160);
	$pdf->SetFont('arial','',10);
	$pdf->Cell(160,3,(utf8_decode('E-mail')),0,0,'L');
	$pdf->Ln(0);			

	$pdf->SetX(220);
	$pdf->SetFont('arial','',10);
	$pdf->Cell(220,3,(utf8_decode('Site')),0,1,'L');
	$pdf->Ln(2);	
	
	$pdf->SetFont('arial','',10);
	$pdf->Cell(280,1,'','T',1,'C');
	$pdf->Ln(1);				
		
//---------------------------------------------------------------------------------------------		
// PROCESSOS
//---------------------------------------------------------------------------------------------			
	if($not->ler()>0){					
		while($not->ini()){	
			$nome_razao 		   = $not->nome_razao;
			$residencial		   = $not->residencial;
			$celular			   = $not->celular;
			$email		  		   = $not->email;
			$website	  		   = $not->website;			
	//				$dt_abertura  		   = $data->getDataFormatada($not->dt_abertura);			
		$cont++;
		
		$pdf->SetX(10);
		$pdf->SetFont('arial','',9);
		$pdf->Cell(10,5,$nome_razao,0,0,'L');
		$pdf->Ln(0);
		
		$pdf->SetX(90);
		$pdf->SetFont('arial','',9);
		$pdf->Cell(90,5,$residencial,0,0,'L');
		$pdf->Ln(0);	
		
		$pdf->SetX(125);
		$pdf->SetFont('arial','',9);
		$pdf->Cell(125,5,$celular,0,0,'L');
		$pdf->Ln(0);			
	
		$pdf->SetX(160);
		$pdf->SetFont('arial','',9);
		$pdf->Cell(160,5,$email,0,0,'L');
		$pdf->Ln(0);			
	
		$pdf->SetX(220);
		$pdf->SetFont('arial','',9);
		$pdf->Cell(220,5,$website,0,1,'L');
		$pdf->Ln(0);	

		}
	
	}else{
		$pdf->SetFont('arial','B',12);
		$pdf->Cell(280,5,(utf8_decode('Nenhum dado foi encontrado.')),0,1,'C');			
	}
	if($cont == ""){
		$cont = 0;	
	}
	$pdf->Ln(2);		

	$pdf->SetFont('arial','B',10);
	$pdf->Cell(280,5,utf8_decode('Número de registros listados: ').$cont,'T',1,'C');
	$pdf->Ln(1);		
	
	$pdf->SetFont('arial','',10);
	$pdf->Cell(280,3,'','T',1,'C');
	
		
	$pdf->Output("relatorio_sintetico.pdf","D");
?>